package com.zretc.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zretc.shop.entity.Users;
import com.zretc.shop.mapper.provider.MySqlProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.HashMap;
import java.util.List;

@Mapper
public interface UsersMapper extends BaseMapper<Users>  {
    @Select(value = "select id,username,nickname from users where nickname like '%${name}%' or username like '%${name}%'")
    List<Users> queryUserListByName(String name);

    //-- 组合查询 通过username和nickname进行匹配
    //-- 如果有username参数 则按username进行查询 如果有nickname 则按nickname查询
    //-- 如果两个部有 那么就按两个条件组合查询 如果两个部没有 则查询全部

    @SelectProvider(type = MySqlProvider.class,method = "queryUserByNicknameAndUsernameSql")
    List<HashMap> queryUserByNicknameAndUsername(String username , String nickname);

    @SelectProvider(type = MySqlProvider.class,method = "queryUserByNicknameAndUsernameSql")
    IPage<HashMap> queryUserPageByNicknameAndUsername(Page page, String username, String nickname);
}
